<?php
/**
 * oscshop2 B2C电子商务系统
 *
 * ==========================================================================
 * @link      http://www.oscshop.cn/
 * @copyright Copyright (c) 2015-2017 oscshop.cn. 
 * @license   http://www.oscshop.cn/license.html License
 * ==========================================================================
 *
 * @author    李梓钿
 *
 */
namespace osc\admin\model;
use think\Db;
class Article{

	function validate($data){
		if(empty($data['title'])){
			return ['error'=>'标题必填'];
		}
		
	}
	function add($data){		
			
			$content['title']=$data['title'];			
			$content['status']=1;
			$content['cid']=$data['cid'];
			$content['author']=admin('username');
			$content['create_time']=time();
			
			if($article_id=Db::name('Article')->insert($content,false,true)){
				
				$content_data['content']=$data['content'];
				$content_data['article_id']=$article_id;
				$content_data['seo_keywords']=$data['seo_keywords'];
				$content_data['seo_description']=$data['seo_description'];
				
				Db::name('ArticleData')->insert($content_data,false,true);				
				
				return ['success'=>'发表成功'];
			}else{
				return ['error'=>'发表失败'];
			}	
	}
	
	function edit($data){
		
			$content['title']=$data['title'];			
			$content['status']=1;
			$content['cid']=$data['cid'];
			$content['author']=admin('username');
			$content['create_time']=time();
			
			if(Db::name('Article')->where('id',$data['id'])->update($content,false,true)){
				
				$content_data['content']=$data['content'];				
				$content_data['seo_keywords']=$data['seo_keywords'];
				$content_data['seo_description']=$data['seo_description'];
				
				Db::name('ArticleData')->where('article_id',$data['id'])->update($content_data,false,true);
												
				return ['success'=>'修改成功'];
			}else{
				return ['error'=>'修改失败'];
			}	
	}
}
?>